# -*- coding: utf-8 -*-
"""
   获取股票信息
"""
import urllib.parse

import urllib3


def handler():
    http = urllib3.PoolManager()
    """
    分时线_line
    http://yunhq.sse.com.cn:32041/v1/sh1/line/601377?
    begin=0&end=-1&select=time,price,volume&_=1524196149875
    """
    line_params = {
        "begin": 0,
        "end": -1,
        "select": "time,price,volume",
        "_": 1524196149875
    }
    line_url_str = "http://yunhq.sse.com.cn:32041/v1/sh1/line/%s?%s" % (
        "600050", urllib.parse.urlencode(line_params))
    # headers = {'Content-Type': 'application/json;charset=UTF-8'}
    resp = http.request(method="GET", url=line_url_str)
    if resp.status == 200:
        print(resp.info())
        encoding = 'GB2312'
        data = str(resp.data, encoding)
        print("分时线_line:%s" % data)
        return data
        # 转json数据
        # text = json.loads(data)
        # print(json.dumps(text, ensure_ascii=False, indent=2, separators=(',', ': ')))
    """
    当日成交汇总信息
    http://yunhq.sse.com.cn:32041/v1/sh1/snap/600050?
    select=name,last,chg_rate,change,amount,volume,open,prev_close,ask,bid,high,low,tradephase
    &_=1524196149889"
    """
    t_params = {
        "select": "name,last,chg_rate,change,amount,volume,open,prev_close,ask,bid,high,low,tradephase",
        "_": 1524196149889
    }
    sse_url_t_str = "http://yunhq.sse.com.cn:32041/v1/sh1/snap/%s?%s" % (
        "600050", urllib.parse.urlencode(t_params))

    """
    日k线
    http://yunhq.sse.com.cn:32041/v1/sh1/dayk/600050?
    select=date,open,high,low,close,volume&begin=-2000&end=-1&_=1524211194209"
    """

    dayk_params = {
        "select": "date,open,high,low,close,volume",
        "begin": "-2000",
        "end": "-1",
        "_": "1524211194209",
    }
